package com.huatai.bi.mapper;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.huatai.bi.entity.DataProcessInfoEntity;

import com.huatai.bi.vo.DataByDtIdVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
* @author hecai
* @description 针对表【tb_data_process_info(数据加工详情)】的数据库操作Mapper
* @createDate 2024-06-27 18:35:37
* @Entity com.huatai.bi.DataProcessInfo
*/
public interface DataProcessInfoMapper extends BaseMapper<DataProcessInfoEntity> {

	@Select("${sql}")
	List<JSONObject> getDataPreview(@Param("sql") String sql);

	@Select("SELECT " +
		" a.*, " +
		" b.order_num  " +
		"FROM " +
		" tb_data_process AS a " +
		" LEFT JOIN tb_data_process_info AS b ON a.id = b.dp_id  " +
		"WHERE " +
		" a.dt_id = ${dtId}")
	List<DataByDtIdVo> getDataByDtId(@Param("dtId") Long dtId);

	@Select("select * from tb_data_process_info where dp_id = ${processId} order by order_num desc limit 0,1")
	DataProcessInfoEntity getLatestByProcessId(@Param("processId") Long processId);

	@Select("select * from tb_data_process_info where dp_id = ${processId} and order_num < ${orderNum} order by order_num desc limit 0,1")
	DataProcessInfoEntity getPreviousData(@Param("processId") Long processId,@Param("orderNum") int orderNum);

	@Select("select * from tb_data_process_info  where dp_id in (select id from tb_data_process where is_deleted = 0 and dt_id = ${dtId})")
	List<DataProcessInfoEntity> infoListByDtId(@Param("dtId") Long dtId);

	@Select("select * from tb_data_process_info  where dp_id = ${processId} order by orderNum")
	List<DataProcessInfoEntity> infoListByProcessId(@Param("processId") Long processId);
}




